package com.example.work9.Servlet;

import com.example.work9.Annotation.LoginLog;
import com.example.work9.Objects.User;
import com.example.work9.Utils.GsonUtil;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginServlet {

    @LoginLog
    @RequestMapping("/login")
    public String Login(@RequestBody String json)
    {
        System.out.println(json);

        User user=GsonUtil.JsonToObject(json, User.class);
        String username=user.getUsername();
        String password=user.getPassword();

        if(username.equals(password))
            return GsonUtil.ObjectToJson(new User(username, password),User.class);

        return "";
    }
}
